import axios from 'axios'
import apiNo from '@/config/api'
import store from '@/store'
const instance = axios.create({
  baseURL: apiNo.baseURL || window.baseURL,
  timeout: 10 * 1000,
  responseType: 'json',
  headers: { 'content-type': 'application/x-www-form-urlencoded' }
})
// 添加响应拦截器
instance.interceptors.response.use(res => {
  console.log(res)
  let { data } = res
  return data
}, error => {
  store.dispatch('toast', '数据获取失败，请稍后再试')
  return error
})

async function post (type, params, options) {
  if (!type) { throw new Error({ msg: '接口类型不可遗漏' }) }
  let res = await instance.post(`${apiNo[type]}/`, params, options)
  return res
}

class Api {

}
const api = new Api()
export default api
